﻿
using Newtonsoft.Json;
using RTW.OA.Areas.Personal.Servers;
using RTW.OA.Models;
using RTW.Utils.Utils;
using System;
using System.Collections.Generic;
using System.Web.Mvc;

namespace RTW.OA.Areas.Personal.Controllers
{
    public class WorkPlanController : Controller
    {
	      private WorkPlanServers workplanServers;

		    public WorkPlanController()
			{
				workplanServers = new WorkPlanServers();
			}


		// GET: Personal/WorkPlan
        public ActionResult Index()
        {
		      		
           return View();
        }

		// GET: Personal/WorkPlan/Edit/5
        public ActionResult Edit(int? id)
        {
				                              ViewBag.TYPEData = workplanServers.GetTYPE();
                               var model = new work_plan();
            if (id != null)
            {
                ViewBag.Title = "编辑工作计划";
                model = GetModel(id.Value.ToString());
            }
            else
            {
                ViewBag.Title = "新建工作计划";
            }
            return View(model);
        }

		// POST: Personal/WorkPlan/Edit/5
        [HttpPost]
        public ActionResult Edit(int? id, work_plan model)
        {
			                        ViewBag.TYPEData = workplanServers.GetTYPE();
                               try
            {
                if (id == null || id == 0)
                {
					workplanServers.Add(model);
                    ViewBag.msg = "新增工作计划信息成功！";
                    model = new work_plan();

                }
                else
                {
					workplanServers.Update(model);
                    ViewBag.msg = "修改工作计划信息成功！";

                }
            }
            catch
            {
                ViewBag.msg = "提交出现错误！";
            }

            return View(model);
        }

		// GET: Personal/WorkPlan/Delete/5
        public ActionResult Delete(int id)
        {
		    if (id != 0)
            {
                workplanServers.Del(id.ToString());
                ViewBag.msg = "删除工作计划信息成功！";                   
            }    
            return Content("");
        }


		 #region //GetData
		public string GetTableJsonResult(
		      				   )
        {
            var list = workplanServers.GetData();
            return JsonConvert.SerializeObject(list);
        }

		public work_plan GetModel(string id)
        {
            var model = workplanServers.GetModelById(id);
            return model;
        }

		 #endregion //GetData
	}
}